#include"serviceview_console_impl.h"
#include<getch.h>
#include<string.h>
using namespace std;
//using namespace MC;



 ServiceViewConsoleImpl:: ServiceViewConsoleImpl()
 {
 		m_pService=new Service_impl;

 }
 int ServiceViewConsoleImpl::menu(void)
{
	system("clear");
 	puts("╭═════════════════════■□■□══════════╮");  
    puts("│          ZhiZhen Conmpany         │");  
    puts("╰════════════■□■□═══════════════════╯");  
	puts("---【1】添加部门*********【2】删除部门----");
	puts("---【3】部门列表*********【4】添加员工----");
	puts("---【5】删除员工*********【6】修改信息----");
	puts("---【7】部门员工*********【8】所有员工----");
	puts("--------------【9】退出----------------");
	char ch=getch();
	return ch-'0'+5;
}
 void ServiceViewConsoleImpl::run(void)
 {
 	while(1)
 	{
 	
 		switch(menu())
 		{
 			case AddDept: addDept();break;
 			case DeleteDept: deleteDept();break;
 			case ListDept:listDept();break;
 			case AddEmp:addEmp();break;
 			case DeleteEmp:deleteEmp();break;
 			case ModifyEmp:modifyEmp();break;
 			case ListEmp:listEmp();break;
 			case ListAllEmp:listAllEmp();break;
 			case Quit:return;

 		}
 		cout<<"按任意键继续"<<endl;
 		getchar();
 	}
 }
 void ServiceViewConsoleImpl::addDept(void)
 {
 	cout<<"please input Department name:"<<endl;
 	char strname[20]={};
 	cin>>strname;
 	Department dp;
 	strcpy(dp.m_strName,strname);
 	Tools tools;
 	int id=tools.get_id(ID_PATH);
 	dp.m_nid=id;
 	Department dp1=dp;
 	
 	m_pService->addDept(dp1);
 	
 	cout<<"create new Department success!"<<endl;
 	getchar();

 }
 void ServiceViewConsoleImpl::deleteDept(void)
 {
 	cout<<"please input delete Department id:"<<endl;
 	int id;
 	cin>>id;
 	if(m_pService->deleteDept(id))
 	{
 		cout<<"delete success!"<<endl;
 	}
 	else
 	{
 		cout<<"delete failed!"<<endl;
 	}
 }
 void ServiceViewConsoleImpl::listDept(void)
 {
 	cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
 	m_pService->listDept();
 	cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;

 }
 void ServiceViewConsoleImpl::addEmp(void)
 {
 	Tools tools;
 	cout<<"请输入员工姓名、性别和年龄："<<endl;
 	Employee em;
 	cin>>em.m_strName>>em.m_bGender>>em.m_nAge;
 	em.m_nid=tools.get_id(ID_PATH);
 	cout<<"请输入部门id:";
 	int id;
 	cin>>id;
 	if(m_pService->addEmp(id,em))
 	{
 		cout<<"添加员工成功！"<<endl;
 	}
 	else
 	{
 		cout<<"添加失败！"<<endl;
 	}
 	getchar();

 }
 void ServiceViewConsoleImpl::deleteEmp(void)
 {
 	cout<<"请输入员工id："<<endl;
 	int id;
 	cin>>id;
 	if(m_pService->deleteEmp(id))
 	{
 		cout<<"删除员工成功！"<<endl;
 	}
 	else
 	{
 		cout<<"删除失败！"<<endl;
 	}
 	getchar();

 }
 void ServiceViewConsoleImpl::modifyEmp(void)
 {
 	cout<<"请输入员工姓名、性别和年龄："<<endl;
 	Employee em;
 	cin>>em.m_strName>>em.m_bGender>>em.m_nAge;
 	cout<<"请输入部门id:";
 	int id;
 	cin>>id;
 	if(m_pService->modifyEmp(id,em))
 	{
 		cout<<"修改员工信息成功！"<<endl;
 	}
 	else
 	{
 		cout<<"修改员工信息失败！"<<endl;
 	}
 	getchar();
 }
 void ServiceViewConsoleImpl::listEmp(void)
 {
 	cout<<"请输入部门id:"<<endl;
 	int id;
 	cin>>id;
 	vector<Employee> v= m_pService->listEmp(id);
 	cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
 	for(unsigned int i=0;i<v.size();i++)
 	{
 		
 		cout<<v[i]<<endl;
 		cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;	
 	}
 	getchar();
 }
 void ServiceViewConsoleImpl::listAllEmp(void)
 {
 	cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
 	m_pService->listAllEmp();
 	cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;

 }
 ServiceViewConsoleImpl::~ServiceViewConsoleImpl()
 {
 	delete m_pService;
 }
